<template>
	<view class="start-index">
		<!-- 1.首页 -->
		<scroll-view :style="{'height':scrollViewHeight+'px'}" scroll-y enable-back-to-top
			@scrolltolower="tabbarPageScrollLower">
			<Home ref="home" @actionEventManager="homeEventManager"></Home>
		</scroll-view>

		<!-- 自动登录 -->
		<AutoLoginManager ref="autoLoginManager" @actionEventManager="loginSuccessManager" />

	</view>
</template>

<script>
	import Home from '@/pages/root/home.vue'

	import AutoLoginManager from '@/components/AutoLogin/AutoLoginManager.vue'

	export default {
		components: {
			Home,
			AutoLoginManager,

		},
		data() {
			return {

				// 自定义底栏对应页面的加载情况
				tabberPageLoadFlag: [],

				windowHeight: 0,
				scrollViewHeight: 0,
			}
		},
		onLoad(options) {


			console.log('页面加载')
		},
		onReady() {
			console.log('页面初次显示')
			var windowHeight = uni.getSystemInfoSync().windowHeight;
			var safeArea = uni.getSystemInfoSync().safeArea.bottom - uni.getSystemInfoSync().safeArea.height;
			var vuex_custom_bar_height = this.vuex_custom_bar_height;
			var statusBarHeight = uni.getSystemInfoSync().statusBarHeight;
			this.windowHeight = windowHeight - vuex_custom_bar_height - safeArea - statusBarHeight;
			this.scrollViewHeight = windowHeight;
		},
		onShow() {
			console.log('页面显示')
		},

		onHide() {
			console.log('页面隐藏')
		},
		onUnload() {
			console.log('页面卸载')
		},
		onBackPress() {
			console.log('页面返回...')
		},

		onReachBottom() {
			console.log('下拉加载...')
		},
		onPageScroll() {
			console.log('页面滚动...')
		},
		onPullDownRefresh() {
			console.log('上拉刷新...')
		},





		onShareAppMessage() {

			var shareInfo = '';
			var memberId = uni.getStorageSync('openid')

			var url = '/pages/root/main?share=true&openid=' + memberId;

			return {
				title: '赶紧测测',
				path: url,
				desc: '测爱好、测智商、测性格、测姻缘，就来赶紧测测',
				imageUrl: 'https://ganjincece1.oss-cn-hangzhou.aliyuncs.com/App/logo.jpg'
			}
		},


		onShareTimeline() {

			var shareInfo = '';
			var memberId = uni.getStorageSync('openid')

			var url = '/pages/root/main';

			return {
				title: '测爱好、测智商、测性格、测姻缘，就来赶紧测测',
				imageUrl: 'https://ganjincece1.oss-cn-hangzhou.aliyuncs.com/App/logo.jpg',
				imagePreviewUrl: 'https://ganjincece1.oss-cn-hangzhou.aliyuncs.com/App/logo.jpg',
				path: url,
				query: 'share=true&openid=' + memberId,

			}
		},




		methods: {
			// 切换导航
			switchTabbar(index) {
				if (index === 1) {
					if (this.$refs.find) {
						this.$refs.find.loginSuccessManager();

						// 第一次加载
						if (this.firstLoadFind === false) {
							this.$refs.find.tabActive = '全部';
							this.firstLoadFind === true;
						}
					}
				}
				this._switchTabbarPage(index)
			},


			// 瀑布流导航页面滚动到底部
			tabbarPageScrollLower(e) {
				// if (this.currentIndex === 2) {
				//   this.$refs.discovery.getRandomData && this.$refs.discovery.getRandomData()
				// }
			},

			// 切换导航页面
			_switchTabbarPage(index) {
				const selectPageFlag = this.tabberPageLoadFlag[index]
				if (selectPageFlag === undefined) {
					return
				}
				if (selectPageFlag === false) {
					this.tabberPageLoadFlag[index] = true
				}
				this.currentIndex = index
			},


			//////////////////////////////////////////////////////////////////////////////////////////   
			//  首页回调
			homeEventManager(method, item, cname, realItem) {
				if (method === 'login') {
					this.autoLoginManager();
				}
			},

			discoveryEventManager(method, item, cname, realItem) {
				if (method === 'login') {
					this.autoLoginManager();
				}
			},
			mineEventManager(method, item, cname, realItem) {
				if (method === 'login') {
					this.autoLoginManager();
				} else if (method === 'directToOrder') {
					this.switchTabbar(1);
				}
			},

			////////////////////////////////////////////////////////////////////////////////////////// 
			// 自动登录
			autoLoginManager() {
				
				this.$refs.autoLoginManager.loginManager()
			},

			// 登录成功方法
			loginSuccessManager(method, item, cname, realItem) {
				if (method === 'loginSuccess') {
					this.$refs.home.loginSuccessManager();

				}
			},

			////////////////////////////////////////////////////////////////////////////////////////// 
			// 支付成功，跳转到待接单订单页面，
			directToOrderAndChangeToWait() {
				this.switchTabbar(1);
				this.$refs.find.reloadAll();
			},
			////////////////////////////////////////首页////////////////////////////////////////////////// 
			homeDirectToOrderConfirm() {
				this.switchTabbar(0);
				this.$refs.home.jikuaidiManager();
			}


		}
	}
</script>

<style lang="scss" scoped>
</style>